package com.mdinfo.gw.door.mapper

import com.baomidou.mybatisplus.mapper.BaseMapper
import com.mdinfo.gw.door.bean.DoorOpenTime
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select

/**
 * Created by Administrator on 2018/2/6.
 */
interface DoorOpenTimeMapper : BaseMapper<DoorOpenTime>{

    /**查询某个门序号最大的开放时间*/
    @Select("""<script>
        select * from door_open_time t
        where t.doorId=#{doorId}
        order by t.orderNum
        desc limit 0,1
    </script>""")
    fun getMaxOrder(doorId:Int):DoorOpenTime

    /**列表查询*/
    @Select("""<script>
        select * from door_open_time t where 1=1
        <if test="name!=null">
            and t.name like CONCAT("%",#{name},"%")
        </if>
        order by t.createTime desc
        limit #{start}, #{num}
    </script>""")
    fun listQuery(@Param("start")start:Int,
                  @Param("num")num:Int,
                  @Param("name")name:String?)
            :List<DoorOpenTime>

    /**列表查询总数*/
    @Select("""<script>
        select count(1) from door_open_time t where 1=1
        <if test="name!=null">
            and t.name like CONCAT("%",#{name},"%")
        </if>
    </script>""")
    fun countListQuery(@Param("start")start:Int,
                  @Param("num")num:Int,
                  @Param("name")name:String?)
            :Int
}